<?php

//namespace AlibabaCloud\SDK\Ali_sms;
namespace utils;
//use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
//use Darabonba\OpenApi\Models\Config;
//use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;

use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
use Darabonba\OpenApi\Models\Config;

class ali_sms {

    /**
     * 使用AK&SK初始化账号Client
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Dysmsapi
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        $config = new Config([]);
        $config->protocol = "HTTP";
        $config->accessKeyId = $accessKeyId;
        $config->accessKeySecret = $accessKeySecret;
        return new Dysmsapi($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function send($phone,$data){
        $client = self::createClient($GLOBALS["sms_key"],$GLOBALS["sms_secret"]);
        // 1.发送短信
        $sendReq = new SendSmsRequest([
            "phoneNumbers" => $phone,
            "signName" => $GLOBALS["sms_sign_name"],
            "templateCode" => $GLOBALS["sms_code_notify"],
            "templateParam" => json_encode($data)
        ]);
        $sendResp = $client->sendSms($sendReq);
        return get_object_vars($sendResp->body);

    }
    public static function send_by_code($phone,$code,$data){
        $client = self::createClient($GLOBALS["sms_key"],$GLOBALS["sms_secret"]);
        // 1.发送短信
        $sendReq = new SendSmsRequest([
            "phoneNumbers" => $phone,
            "signName" => $GLOBALS["sms_sign_name"],
            "templateCode" => $code,
            "templateParam" => json_encode($data)
        ]);
        $sendResp = $client->sendSms($sendReq);
        return get_object_vars($sendResp->body);

    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . 'api' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}


